package com.ruoyi.web.controller.medicine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.medicine.domain.HisMedicineOrderRep;
import com.ruoyi.medicine.service.IHisMedicineOrderRepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 入库记录信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/medicine/rep")
public class HisMedicineOrderRepController extends BaseController
{
    @Autowired
    private IHisMedicineOrderRepService hisMedicineOrderRepService;

    /**
     * 查询入库记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisMedicineOrderRep hisMedicineOrderRep)
    {
        startPage();
        List<HisMedicineOrderRep> list = hisMedicineOrderRepService.selectHisMedicineOrderRepList(hisMedicineOrderRep);
        return getDataTable(list);
    }

    /**
     * 导出入库记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:export')")
    @Log(title = "入库记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HisMedicineOrderRep hisMedicineOrderRep)
    {
        List<HisMedicineOrderRep> list = hisMedicineOrderRepService.selectHisMedicineOrderRepList(hisMedicineOrderRep);
        ExcelUtil<HisMedicineOrderRep> util = new ExcelUtil<HisMedicineOrderRep>(HisMedicineOrderRep.class);
        util.exportExcel(response, list, "入库记录信息数据");
    }

    /**
     * 获取入库记录信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:query')")
    @GetMapping(value = "/{repId}")
    public AjaxResult getInfo(@PathVariable("repId") Long repId)
    {
        return success(hisMedicineOrderRepService.selectHisMedicineOrderRepByRepId(repId));
    }

    /**
     * 新增入库记录信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:add')")
    @Log(title = "入库记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HisMedicineOrderRep hisMedicineOrderRep)
    {
        hisMedicineOrderRep.setRepPerson(getUserId());
        hisMedicineOrderRep.setCreateTime(new Date());
        return toAjax(hisMedicineOrderRepService.insertHisMedicineOrderRep(hisMedicineOrderRep));
    }

    /**
     * 修改入库记录信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:edit')")
    @Log(title = "入库记录信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisMedicineOrderRep hisMedicineOrderRep)
    {
        return toAjax(hisMedicineOrderRepService.updateHisMedicineOrderRep(hisMedicineOrderRep));
    }

    /**
     * 删除入库记录信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:rep:remove')")
    @Log(title = "入库记录信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repIds}")
    public AjaxResult remove(@PathVariable Long[] repIds)
    {
        return toAjax(hisMedicineOrderRepService.deleteHisMedicineOrderRepByRepIds(repIds));
    }
}
